import { shapeType } from "src/types/drawBoard";
import Base from "./Base";
import utils from "src/utils";

export interface ArrowProps {
  x: number;
  y: number;
  width: number;
  height: number;
  borderWidth?: number;
  borderColor?: string;
  bgcolor?: string;
}

export default class extends Base {
  constructor(option: ArrowProps) {
    super(shapeType.arrow)
    utils.object.Assign(option, this.props)
  }
  draw(ctx: CanvasRenderingContext2D, osCtx: OffscreenCanvasRenderingContext2D): void {
    const { x, y, width, height } = this.props

    const offsetX = width*0.1, offsetY = height*0.3

    ctx.save()

    this.transform(ctx)

    ctx.beginPath()
    this.initOptions(ctx, 1)
    ctx.moveTo(x, y + height / 2)
    ctx.lineTo(x + width - offsetX, y + height / 2 - offsetY)
    ctx.lineTo(x + width - offsetX * 1.1, y)
    ctx.lineTo(x + width, y + height / 2)
    ctx.lineTo(x + width - offsetX * 1.1, y + height)
    ctx.lineTo(x + width - offsetX, y + height / 2 + offsetY)
    ctx.closePath()
    ctx.fill()

    ctx.restore()

    // 镜像画布
    this.drawMirror(osCtx)
  }
}